<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<%
  String ctxPath = request.getContextPath();
%>

<%@ include file="/ep/portlet/portletEntityPreferenceValuePopupHelper.jsp" %>

<script language="JavaScript">

//
//
//
function doCancel() {
  var action = '<c:url value="/ep/portletEntityPreferencesView.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + document.portletEntityPreferenceForm.programId.value;

  document.portletEntityPreferenceForm.action = action;
  document.portletEntityPreferenceForm.submit();
}

function doPortletEntityView() {
  var action = '<c:url value="/ep/portletEntityView.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + document.portletEntityPreferenceForm.programId.value;

  document.portletEntityPreferenceForm.action = action;
  document.portletEntityPreferenceForm.submit();
}

function doCreateEntityPreferenceValue() {
  <c:url var="url" value="/ep/portletEntityPreferenceValueNew.do">
    <c:param name="callback" value="addPreferenceValue"/>
  </c:url>
  var popupUrl = "<c:out value='${url}'/>";

  portletEntityPreferenceValuePopup(popupUrl);
}

function addPreferenceValue(preferenceValue) {
  <c:url var="url" value="/ep/portletEntityPreferenceEdit.do">
    <c:param name="prefAction" value="addValue"/>
  </c:url>
  var action = "<c:out value='${url}'/>";
  action += "&newValue=" + preferenceValue;
  
  document.portletEntityPreferenceForm.action = action;
  document.portletEntityPreferenceForm.submit();
}

function doEditEntityPreferenceValue(preferenceValue) {
  <c:url var="url" value="/ep/portletEntityPreferenceValueEdit.do">
    <c:param name="callback" value="updatePreferenceValue"/>
  </c:url>
  var popupUrl = "<c:out value='${url}'/>";
  popupUrl += "&preferenceValue=" + preferenceValue;

  portletEntityPreferenceValuePopup(popupUrl);
}

function updatePreferenceValue(oldPreferenceValue,preferenceValue) {
  <c:url var="url" value="/ep/portletEntityPreferenceEdit.do">
    <c:param name="prefAction" value="editValue"/>
  </c:url>
  var action = "<c:out value='${url}'/>";
  action += "&newValue=" + preferenceValue + "&oldValue=" + oldPreferenceValue;
  
  document.portletEntityPreferenceForm.action = action;
  document.portletEntityPreferenceForm.submit();
}

function doDeleteEntityPreferenceValue(preferenceValue) {
  if(confirm('<bean:message key="ep.portlet.alert.confirmDeletePortletEntityPreferenceValue" bundle="ep.messages"/>')) {
    <c:url var="url" value="/ep/portletEntityPreferenceEdit.do">
      <c:param name="prefAction" value="deleteValue"/>
    </c:url>
    var action = "<c:out value='${url}'/>";
    action += "&deleteValue=" + preferenceValue;
  
    document.portletEntityPreferenceForm.action = action;
    document.portletEntityPreferenceForm.submit();
  }
}

function checkRequiredFields(form) {
<c:if test="${portletEntityPreferenceForm.map.oldPreferenceName == ''}">
  <c:if test="${empty valueList}">
    alert('<bean:message key='ep.alert.empty.portlet.entity.preference.values' bundle="ep.messages"/>');
    return false;
  </c:if>
</c:if>
<c:if test="${portletEntityPreferenceForm.map.oldPreferenceName != ''}">
  <c:if test="${empty valueList}">
    if((confirm('<bean:message key='ep.alert.empty.portlet.entity.preference.values.confirm' bundle="ep.messages"/>')) == false)
      return false;
  </c:if>
</c:if>

  if(form.preferenceName.value == "") {
    alert('<bean:message key='ep.alert.empty.portlet.entity.preference.name' bundle="ep.messages"/>');
    return false;
  }
  
  if((form.editable[0].checked != true) && (form.editable[1].checked != true)) {
    alert('<bean:message key='ep.alert.editable.not.selected' bundle="ep.messages"/>');
    return false;
  }
    
  var tmp_string = form.preferenceName.value;
  for (var i=0; i < tmp_string.length; i++) {
    if(tmp_string.substring(i, i+1) != " ") {
      return true;
    }
  }
  
  alert('<bean:message key='ep.alert.portlet.entity.preference.name.all.spaces' bundle="ep.messages"/>');
  return false;
}

</script>

<c:set var="editImg">
<img src="<%= ctxPath %>/ep/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.edit" bundle="ep.messages"/>" title="<bean:message key="image.alt.edit" bundle="ep.messages"/>">
</c:set>
<c:set var="deleteImg">
<img src="<%= ctxPath %>/ep/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.delete" bundle="ep.messages"/>" title="<bean:message key="image.alt.delete" bundle="ep.messages"/>">
</c:set>

<%
  java.util.HashMap map = new java.util.HashMap();
  String pId = request.getParameter("programId");
  map.put("programId",pId);
  pageContext.setAttribute("pagetabParam",map);
%>
    
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
      <c:if test="${portletEntityPreferenceForm.map.oldPreferenceName == ''}">
        <bean:message key="ep.portlet.entity.preference.new.page.title" bundle="ep.messages"/>
      </c:if>
      <c:if test="${portletEntityPreferenceForm.map.oldPreferenceName != ''}">
        <bean-el:message key="ep.portlet.entity.preference.edit.page.title" bundle="ep.messages" arg0="${portletEntityPreferenceForm.map.preferenceName}"/>
      </c:if>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <!- place body here -->

      <html-el:form action="/ep/portletEntityPreferenceSave.do" onsubmit="return checkRequiredFields(this);">

      <html-el:hidden property="programId" value="${portletEntityPreferenceForm.map.id}"/>
      <html-el:hidden property="oldPreferenceName" value="${portletEntityPreferenceForm.map.oldPreferenceName}"/>
      
      <input type="hidden" name="forward" value="<c:out value="${epActionForward.map.forward}"/>">

      <div class="pageSubtitle">
        <span class="left"><bean:message key="ep.portlet.entity.preference.information" bundle="ep.messages"/></span>
        <span class="right">&nbsp;</span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="label"><bean:message key="ep.portlet.entity.preference.name" bundle="ep.messages"/>*:</td>
        <td class="labelField"><input type="text" name="preferenceName" value="<c:out value="${portletEntityPreferenceForm.map.preferenceName}"/>" size="50" maxlength="80"/>
        </td>
      </tr>

      <tr>
        <td class="label"><bean:message key="ep.portlet.entity.preference.editable" bundle="ep.messages"/>*:</td>
        <td class="labelField"><html-el:radio property="editable" value="false"/><bean:message key="ep.yes" bundle="ep.messages"/>&nbsp;<html-el:radio property="editable" value="true"/><bean:message key="ep.no" bundle="ep.messages"/>
        </td>
      </tr>
      
      </table>

      <div class="pageSubtitle">
        <span class="left"><bean:message key="ep.portlet.entity.preference.values" bundle="ep.messages"/></span>
        <span class="right"><input type="button" class="inputButton" value="<bean:message key="button.new.preference.value" bundle="ep.messages"/>" onclick="doCreateEntityPreferenceValue()"></span>
      </div>

      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Preference value table" width="100%">
        <tr class="listHeader">
          <th id="Name" align="left"><bean:message key="ep.header.name.portlet.entity.preference.value" bundle="ep.messages"/></th>
          <th id="Actions" align="left" nowrap><bean:message key="ep.header.actions" bundle="ep.messages"/></th>
        </tr>

              <logic:iterate id="item" name="valueList" indexId="index">
                <tr class="<%= index.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
                  <td headers="Name"><c:out value="${item}"/></td>
                  <td headers="Actions">
                    <a href="#" onclick="doEditEntityPreferenceValue('<c:out value="${item}"/>');"><c:out
                    value='${editImg}' escapeXml="false"/></a>
                    <a href="#" onclick="doDeleteEntityPreferenceValue('<c:out value="${item}"/>');"><c:out
                    value='${deleteImg}' escapeXml="false"/></a>
                  </td>
                </tr>
             </logic:iterate>

      </table>

      <div class="pageButtonWrap" align="right">
        <input type="reset" name="resetBtn" value="<bean:message key='button.reset' bundle="ep.messages"/>" class="inputButton">
        &nbsp;&nbsp;
        <input type="button" name="cancelData" class="inputButton" value="<bean:message key='button.cancel' bundle="ep.messages"/>" onclick="doCancel()">
        <input type="submit" name="saveData" class="inputButton" value="<bean:message key='button.save' bundle="ep.messages"/>">
      </div>
      </html-el:form>
    </td>
  </tr>
</table>

